﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface IProductTagMappingService
    {
        IQueryable<ProductTagMapping> GetProductTagMappings();
        ProductTagMapping GetProductTagMapping(int id);
        void CreateProductTagMapping(ProductTagMapping productTagMapping);
        void DeleteProductTagMapping(int id);
        void SaveProductTagMapping();
    }
    
    public class ProductTagMappingService : IProductTagMappingService
    {
        private readonly IProductTagMappingRepository productTagMappingRepository;
        private readonly IUnitOfWork unitOfWork;
        public ProductTagMappingService(IProductTagMappingRepository productTagMappingRepository, IUnitOfWork unitOfWork)
        {
            this.productTagMappingRepository = productTagMappingRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region IProductTagMappingService Members

        public IQueryable<ProductTagMapping> GetProductTagMappings()
        {
            var productTagMappings = productTagMappingRepository.GetAll();
            return productTagMappings;
        }

        public ProductTagMapping GetProductTagMapping(int id)
        {
            var productTagMapping = productTagMappingRepository.GetById(id);
            return productTagMapping;
        }

        public void CreateProductTagMapping(ProductTagMapping productTagMapping)
        {
            productTagMappingRepository.Add(productTagMapping);
            SaveProductTagMapping();
        }

        public void DeleteProductTagMapping(int id)
        {
            var productTagMapping = productTagMappingRepository.GetById(id);
            productTagMappingRepository.Delete(productTagMapping);
            SaveProductTagMapping();
        }

        public void SaveProductTagMapping()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}